package com.woniu.service;

import com.rabbitmq.client.Channel;
import com.woniu.adapter.BuyRecordAdapter;
import com.woniu.service.bean.AddBuyRecord;
import com.woniu.service.bean.AddBuyRecordHandler;
import com.woniu.service.bean.UpdateBuyRecord;
import com.woniu.service.bean.UpdateBuyRecordHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
@Transactional
public class BuyRecordService implements AddBuyRecordHandler, UpdateBuyRecordHandler {

    @Autowired
    private BuyRecordAdapter buyRecordAdapter;

    @Override
    public int action(AddBuyRecord command) {
        return buyRecordAdapter.addOrderSucceed(command);
    }


    @Override
    public void action(UpdateBuyRecord command) {
        buyRecordAdapter.updateBuyRecord(command);
    }

    /**
     * 根据id获取信息
     * @param id
     * @return
     */
    public AddBuyRecord getById(Integer id){
       return buyRecordAdapter.getById(id);
    }

    /**
     * 根据id删除记录
     */
    public void deleteById(Integer id){
        buyRecordAdapter.deleteById(id);
    }
}
